home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_02
/
1002022a
< prev
next >
Wrap
Text File
|
1991-12-03
|
405b
|
28 lines
#include <stdio.h>
#define STACK_TOP 50
static int stack[STACK_TOP];
static size_t stack_ptr = 0;
void push(int value)
{
if (stack_ptr < STACK_TOP)
stack[stack_ptr++] = value;
else
fprintf(stderr, "Stack full: discarding %d\n", value);
}
int pop(void)
{
if (stack_ptr > 0)
return stack[--stack_ptr];
else {
fprintf(stderr, "Stack empty\n");
return 0;
}
}